import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);
function sessionStg(state) {
  sessionStorage.setItem("state", JSON.stringify(state));
}
export default new Vuex.Store({
  state: {
    isPC: true, // 是否为pc端
    title: "", // 标签页title
    isShowNav: true, // 是否显示底部导航栏, 移动端
    navRouterWeb: "companyInfo", // 当前的nav-barRouter名,web端
    checkStatus: "0", // 公司审核状态 (0:待提交 1:平台审核中 2:通联审核中 3:平台拒绝 4：通联拒绝 5：审核通过
    isSign: true, // 是否签订了云商通的电子协议
    mobile: "", // 手机号
    company: "", // 公司
    validateMobile: false, // 是否已经验证手机号
    hadPayPsw: false, //是否已经设置了密码
    loading: false, // 是否显示loading框
    balance: 0, // 余额
    closeEye: false, // 是否隐藏
    isRead: false, // 是否点进了消息通知
    readNum: 0 // 未读消息条数
  },
  mutations: {
    changeIsPC(state, isPC) {
      state.isPC = isPC;
      sessionStg(state);
    },
    changeTitle(state, title) {
      state.title = title + "-企业端-好融艺";
      window.document.title = state.title;
      sessionStg(state);
    },
    changeIsShowNav(state, isShowNav) {
      state.isShowNav = isShowNav;
      sessionStg(state);
    },
    changeNavRouterWeb(state, routerName) {
      state.navRouterWeb = routerName;
      sessionStg(state);
    },
    changeCheckStatus(state, checkStatus) {
      state.checkStatus = checkStatus;
      sessionStg(state);
    },
    changeSignStatus(state, isSign) {
      state.isSign = isSign;
      sessionStg(state);
    },
    changeMobile(state, mobile) {
      state.mobile = mobile;
      sessionStg(state);
    },
    changeCompany(state, company) {
      state.company = company;
      sessionStg(state);
    },
    changeValidateMobile(state, validateMobile) {
      if (validateMobile === "YES") {
        state.validateMobile = true;
      } else {
        state.validateMobile = false;
      }
      sessionStg(state);
    },
    changeHadPayPsw(state, hadPayPsw) {
      state.hadPayPsw = hadPayPsw;
      sessionStg(state);
    },
    changeLoading(state, loading) {
      state.loading = loading;
      sessionStg(state);
    },
    changeBalance(state, balance) {
      state.balance = balance;
      sessionStg(state);
    },
    changeCloseEye(state, closeEye) {
      state.closeEye = closeEye;
      sessionStg(state);
    },
    changeRead(state, isRead) {
      state.isRead = isRead;
      sessionStg(state);
    },
    changeReadNum(state, readNum) {
      state.readNum = readNum;
      sessionStg(state);
    }
  },
  actions: {
    changeIsPC(context, isPC) {
      context.commit("changeIsPC", isPC);
    },
    changeTitle(context, title) {
      context.commit("changeTitle", title);
    },
    changeIsShowNav(context, isShowNav) {
      context.commit("changeIsShowNav", isShowNav);
    },
    changeNavRouterWeb(context, routerName) {
      context.commit("changeNavRouterWeb", routerName);
    },
    changeCheckStatus(context, checkStatus) {
      context.commit("changeCheckStatus", checkStatus);
    },
    changeSignStatus(context, isSign) {
      context.commit("changeSignStatus", isSign);
    },
    changeMobile(context, mobile) {
      context.commit("changeMobile", mobile);
    },
    changeCompany(context, company) {
      context.commit("changeCompany", company);
    },
    changeValidateMobile(context, validateMobile) {
      context.commit("changeValidateMobile", validateMobile);
    },
    changeHadPayPsw(context, hadPayPsw) {
      context.commit("changeHadPayPsw", hadPayPsw);
    },
    changeLoading(context, loading) {
      context.commit("changeLoading", loading);
    },
    changeBalance(context, balance) {
      context.commit("changeBalance", balance);
    },
    changeCloseEye(context, closeEye) {
      context.commit("changeCloseEye", closeEye);
    },
    changeRead(context, isRead) {
      context.commit("changeRead", isRead);
    },
    changeReadNum(context, readNum) {
      context.commit("changeReadNum", readNum);
    }
  }
});
